//
//  MoreViewController.m
//  meiyaya
//
//  Created by 张领瑞 on 2017/9/6.
//  Copyright © 2017年 ShiFeiEr. All rights reserved.
//

#import "MoreViewController.h"
#import "PrefixHeader.pch"
@interface MoreViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property (nonatomic,strong)NSMutableArray *datasourceArray;

@property (nonatomic,strong)UICollectionView * collectionView;

@end

@implementation MoreViewController
#pragma mark 懒加载 datasourceArray collectionView
-(NSMutableArray *)datasourceArray{
    if (_datasourceArray) {
        _datasourceArray = [[NSMutableArray alloc]init];
    }
    return _datasourceArray;
}

-(UICollectionView *)collectionView{
    if (_collectionView == nil) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT-self.navigationController.navigationBar.frame.size.height-17) collectionViewLayout:layout];
        self.collectionView.delegate = self;
        self.collectionView.dataSource = self;
        _collectionView.backgroundColor = [UIColor whiteColor];
        
    }
    return _collectionView;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    //设置页面title及cell的reuseIdentifier
    switch (self.classID) {
        case 1002:
            self.reuseIdentifier = @"CollectionViewCell";
            self.title = @"热门课程";
            break;
        case 1003:
            self.reuseIdentifier = @"CollectionViewCell";
            self.title = @"会员课程";
            break;
        case 1004:
            self.reuseIdentifier =  @"BznsInfoCollectionViewCell";
            self.title = @"行业资讯";
            break;
        default:
            break;
    }
    
    //重写导航栏返回按钮
    UIBarButtonItem *backBtnItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"return"] style:UIBarButtonItemStylePlain target:self action:@selector(backToAlivingViewController)];
    backBtnItem.tintColor = [UIColor whiteColor];
    self.navigationItem.leftBarButtonItem = backBtnItem;
    
    //添加colletionview
    [self.view addSubview:self.collectionView];
    //注册cell
    [self.collectionView registerNib:[UINib nibWithNibName:self.reuseIdentifier bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:self.reuseIdentifier];
    //注册头视图
    [self.collectionView registerNib:[UINib nibWithNibName:@"FooterReusableView" bundle:[NSBundle mainBundle]] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"FooterReusableView"];
    
    // Do any additional setup after loading the view.
}
#pragma mark <UICollectionViewDataSource>

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 8;
   // return self.datasourceArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:self.reuseIdentifier forIndexPath:indexPath];
    return cell;
}
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    UICollectionReusableView *view;
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
        view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"FooterReusableView" forIndexPath:indexPath];
    }
    return view;
}



#pragma mark collectionViewLayoutDelegate Method
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    if ([_reuseIdentifier isEqualToString:@"CollectionViewCell"]) {
        return ITEM_SIZE;
    }
    return CGSizeMake(SCREENWIDTH, 100);
}

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(10, 10, 10, 10);
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    return CGSizeMake(SCREENWIDTH, 10);
}

#pragma mark collectionViewDelegate Method 
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    switch (self.classID) {
        case 1002:
           // self.reuseIdentifier = @"CollectionViewCell";
            
        case 1003:
           // self.reuseIdentifier = @"CollectionViewCell";
           
            break;
        case 1004:{
          //  self.reuseIdentifier =  @"BznsInfoCollectionViewCell";
            self.hidesBottomBarWhenPushed = YES;
            DetailInfoViewController *detailInfoVC = [[DetailInfoViewController alloc] init];
            [self.navigationController pushViewController:detailInfoVC animated:YES];
            self.hidesBottomBarWhenPushed = NO;
        }
            break;
        default:
            break;
    }
}



//重写返回按钮响应的方法
-(void)backToAlivingViewController{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
